package com.weactivity.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.weactivity.dto.MessageDTO;
import com.weactivity.entity.Message;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface MessageMapper extends BaseMapper<Message> {
    @Select("select count( r_uid = #{userId} AND `read` = 0  or NULL )" +
            " from message")
    int findUnReadByID(Long userId);

    List<MessageDTO> findAllById(Long userId);

    @Delete("delete from message where nid = #{id}")
    int removeById(int id);

    @Insert("insert into message (s_uid,r_uid,type,`read`,s_time,content,m_subject) values (#{sUid},#{rUid},#{type},#{read},#{sTime},#{content},#{subject});")
    int addSingleMessage(
            @Param("sUid") int sUid,
            @Param("rUid") int rUid,
            @Param("type") int type,
            @Param("read") int read,
            @Param("sTime") String sTime,
            @Param("content") String content,
            @Param("subject") String subject
    );

    @Update("update message set `read` = 1 where nid = #{nid} ;")
    int isRead(int nid);

    @Insert("insert into message (s_uid,r_uid,type,`read`,s_time,content,m_subject) values (0,#{rid},2,0,now(),#{content},#{subject});")
    int sendConfictedMessageToOrg(@Param("rid") int conficetedActOrgId, @Param("content") String content, @Param("subject") String mSubject);

    @Insert("insert into message (s_uid,r_uid,type,s_time,content,m_subject) values (0,#{r_uid},2,#{now},#{content},#{subject});")
    int systemSendSingleConfictMessage(@Param("r_uid") Integer userId,@Param("content") String contentSystemMessageToConfictUser, @Param("subject") String subjectSystemMessageToConfictUsre,@Param("now") String now);

}
